package com.boc.langxiang.ui.adapter.me;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.boc.langxiang.R;
import com.boc.langxiang.contract.me.MyCollectionsActivityContract;
import com.boc.langxiang.entity.response.CollectEntity;
import com.boc.langxiang.manager.PicassoImageLoader;
import com.boc.langxiang.util.StringUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by admin on 2016/6/27.
 */
public class MyCollectionsRVAdapter extends BaseQuickAdapter<CollectEntity> {

    private MyCollectionsActivityContract.View mView;
    private boolean mVisible = false;

    public MyCollectionsRVAdapter(Context context, List<CollectEntity> data, MyCollectionsActivityContract.View view) {
        super(R.layout.item_me_mycollections, data);
        this.mView = view;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final CollectEntity item) {
        helper.setText(R.id.tv_me_collection_title, StringUtil.getValue(item.getTitle()))
                .setText(R.id.tv_me_collection_price, StringUtil.getValue(item.getPrice()))
                .setVisible(R.id.linlayout_me_mycollections, mVisible)
                .setOnClickListener(R.id.iv_me_collection_delete, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mView.delete(helper.getLayoutPosition());
                    }
                });
        PicassoImageLoader.getInstance().displayUrlImage(mContext, item.getPhotourl()
                , (ImageView) helper.getView(R.id.riv_me_collection_bg));
    }

    public void setDeleteIconVisiblity(boolean visible) {
        this.mVisible = visible;
        notifyDataSetChanged();
    }
}
